//package com.xiaoban.exception;
//
//import io.jsonwebtoken.SignatureException;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpStatus;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.ResponseStatus;
//
//import javax.servlet.ServletException;
//import java.io.IOException;
//
///**
// * @author 小班哥
// * @version 1.0
// * @date 2023/8/24 23:53
// * @description 全局异常捕捉类
// */
//@Slf4j
//@ControllerAdvice
//@Component
//public class GlobalExceptionHandler {
//    @ResponseBody
//    @ExceptionHandler(MethodArgumentNotValidException.class)
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    public RestErrorResponse doValidException(MethodArgumentNotValidException exception){
//        StringBuffer stringBuffer = new StringBuffer(exception.getBindingResult().getFieldErrors().toString());
//        int index = stringBuffer.lastIndexOf("default message");
//        String substring = stringBuffer.substring(index);
//        int index1 = substring.indexOf("[");
//        int index2 = substring.indexOf("]]");
//        String error = substring.substring(index1 + 1, index2);
//        log.info("MethodArgumentNotValidException 抛出异常 异常信息{}" , error);
//        return new RestErrorResponse(error);
//    }
//
//    /**
//     * 自定义异常
//     * @param exception
//     * @return
//     */
//    @ResponseBody
//    @ExceptionHandler({OwnErrorMessage.class})
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    public RestErrorResponse OwnErrorException(OwnErrorMessage exception){
//        log.error("自定义异常信息:{}" , exception.getMessage());
//        return new RestErrorResponse(exception.getCode(),exception.getMessage());
//    }
//
//
//    /**
//     * 自定义异常
//     * @param exception
//     * @return
//     */
//    @ResponseBody
//    @ExceptionHandler({AuthenticationException.class , ServletException.class , IOException.class})
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    public RestErrorResponse AuthenticationException(AuthenticationException exception){
//        log.error("AuthenticationException:{}" , exception.getMessage());
//        return new RestErrorResponse(exception.getMessage());
//    }
//
//
//    /**
//     * 捕捉密码错误时的错误，SpringSecurity会抛出一个AuthenticationException的异常
//     * @param exception 错误信息
//     * @return
//     */
////    @ResponseBody
////    @ExceptionHandler(AuthenticationException.class)
////    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
////    public RestErrorResponse AuthenticationExceptionException(AuthenticationException exception){
////        log.info("AuthenticationException抛出的异常信息：{}" , exception);
////        return new RestErrorResponse(exception.getMessage());
////    }
//}
